#ifndef FKDATARECORD_H
#define FKDATARECORD_H

#include <QMap>
#include <QVariant>

#include "FKModelElements.h"

#include "fkdatamodels_global.h"

class FKDataList;

class FKDATAMODELSSHARED_EXPORT FKDataRecord{
public:
    FKDataRecord(FKDataRecord* parent,const QVariant& source=QVariant());
    virtual ~FKDataRecord(){qDeleteAll(_elements);}
    QVariant toVariant()const;
    int row()const{return _row;}
    int prop()const{return _prop;}
    void setData(const int& role, const QVariant& val){_data[role]=val;}
    QVariant data(const int& role)const{return _data.value(role,QVariant());}
    int rowCount()const;
    int columnCount()const;
    FKDataRecord* parent()const{return _parent;}
    FKDataRecord* sibling(const int& row, const int& prop)const;
    FKDataList* element(const int& prop=FKModelElements::defaultElement)const{return _elements.value(prop,0);}
    FKDataList* addElement(const int& prop=FKModelElements::defaultElement);
    FKDataRecord* clone(FKDataRecord* parent)const;
    FKDataRecord* subRecord(const int &row, const int &prop)const;
private:
    FKDataRecord* _parent;
    QMap<int,QVariant> _data;
    QMap<int,FKDataList*> _elements;
    int _row;
    int _prop;
    static const QString ownData;
    friend class FKDataList;
};

class FKDATAMODELSSHARED_EXPORT FKDataList{
public:
    FKDataList(FKDataRecord* parent,const int& prop,const QVariant& source=QVariant());
    ~FKDataList(){qDeleteAll(_data);}
    QVariant toVariant()const;
    FKDataList* clone(FKDataRecord* parent)const;
    int size()const{return _size;}
    FKDataRecord* record(const int &num=0)const{return (num<0 || num>=_size) ? 0 : _data.at(num);}
    FKDataRecord* addRecord();
    bool cloneRecord(const int &num=0, const int &multiplier=1);
private:
    int _size;
    QList<FKDataRecord*> _data;
    FKDataRecord* _parent;
    int _prop;
};

#endif // FKDATARECORD_H



